#e
#Title[puqƂv]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

let Norma=5;//Be̐ݒ
let SpellTimer=9000;//Ԃ̐ݒit[Pʁj
let StepUp=[1,2,3,4];//iKڍs閇ݒi܂܂Őݒ\jBStepUp1`5ibooleanj܂łA͖BtrueɂȂ

#include_function ".\..\txt/DoubleSpoilerData.txt"

    let imgBoss =GetCurrentScriptDirectory ~ "..\lib/dot_sanae.png"; 

    // ʒu
    let xIni    = GetCenterX;
    let yIni    = GetCenterY-50;


    @Initialize {
	SetShotAutoDeleteClip(0,0,0,0);
	SetBulletScorePoint(12,160);
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,5,236,233,262);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
	InitializeAction();
	SetX(GetCenterX);
	SetY(GetClipMinY-100);
        TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	DoubleSpoilerYield;
    }

    @DrawLoop {
	DrawDoubleSpoiler;
	DrawBoss( imgBoss );
    }

    @Finalize {
        DeleteGraphic(imgBoss);
	FinalizeDoubleSpoiler;
    }
	@BackGround
	{


	}

    // C^XN
task TMain 
{
	yield;
	BossShadowAnimation(imgBoss,0,65,65,225);
	movewind;
	standBy;
	Shot;
	Shot2;
	step;
}

task movewind
{
let count=0;
loop(60)
{
SetPlayerY(GetPlayerY+5/60*(60-count));
count+=1;
yield;
}
}

sub standBy//ʒu
{
	SetAction(ACT_MOVE, 30);
	let wIni = 30;
	SetMovePosition03(xIni, yIni, 10,8);
	SetInvincibility(wIni);
	wait(45);
}

let ShotLoop=5;
let ShotWay=8;
let StarWaitTime=210;

task step
{
	while(!StepUp1){yield;}
	ShotLoop=6;
	ShotWay=10;
	StarWaitTime=180;
	while(!StepUp2){yield;}
	ShotLoop=7;
	ShotWay=12;
	StarWaitTime=150;
	while(!StepUp3){yield;}
	ShotWay=14;
	while(!StepUp4){yield;}
	ShotWay=18;
	StarWaitTime=120;
}

task Shot2
{
loop
{
let angle=rand(0,360);
SetAction(ACT_SHOT_A,165);
	RedShot2(angle);
	wait(45);
	BlueShot2(angle);
	wait(120);
	DoubleSpoilermoveToPlayer(rand(40, 60), rand(-10, 10), 30,
                     GetClipMinX + 48, GetClipMinY +  64,
                     GetClipMaxX - 48, GetClipMinY + 144);
	wait(30);
	
}
}

task RedShot2(angle)
{
	loop(ShotLoop)
	{
	ascent(let j in 0..3)
	{
	ascent(let i in 0..ShotWay)
	{	
		DoubleSpoilerCreateShot01(GetX,GetY,2.5,angle+i*360/ShotWay,65,5,"RED",0,2);
	}
	angle+=2.5;
	wait(4);
	}
	angle+=6-2.25;
	wait(8);
	}
}

task BlueShot2(angle)
{
	loop(ShotLoop)
	{
	ascent(let j in 0..3)
	{
	ascent(let i in 0..ShotWay)
	{	
		DoubleSpoilerCreateShot01(GetX,GetY,3.5,angle+i*360/ShotWay,70,5,"BLUE",0,2);
	}
	angle-=2.5;
	wait(4);
	}
	angle-=6-2.25;
	wait(8);
	}
}

task Shot
{
wait(120);
	loop
	{
		StarCentralShot(GetPlayerX,GetClipMinY,125,2.5,90,129,10);
		wait(StarWaitTime);
	}
}

task LayShot(Sobj,r)
{
	let obj = Obj_Create(OBJ_SHOT);
	ObjShot_SetGraphic(obj, 245);
	//ObjShot_SetDelay(obj, delay);
	//ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);

	let X;
	let Y;
	let VanishJudg=false;

	let dis=r*2*sin(72);
	let speed=5;
	let r=0;
	let pangle=90+GetAngleToPlayer-90;
	let GPAngle=GetAngleToPlayer;
	let t=0;

	let X=Obj_GetX(obj);
	let Y=Obj_GetY(obj);
	let JudgCount=0;
	Obj_SetPosition(obj,Obj_GetX(Sobj)+r*cos(Obj_GetAngle(Sobj)+162),Obj_GetY(Sobj)+r*sin(Obj_GetAngle(Sobj)+162));
	loop(floor(dis/speed))
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_BeDeleted(obj)){break;}
		Obj_SetPosition(obj,Obj_GetX(Sobj)+r*cos(Obj_GetAngle(Sobj)),Obj_GetY(Sobj)+r*sin(Obj_GetAngle(Sobj)));
		r+=speed;
		JudgCount+=1;
		yield;
	}
	if(GetCommonDataDefault("Shooting",false))
	{
		if(X<GetClipMaxX && X>GetClipMinX && Y<GetClipMaxY && Y>GetClipMinY && JudgCount<floor(dis/speed))
		{
		BulletColor("GREEN");
			EffectSet(X,Y,"GREEN");
		}
	}
	if(GetCommonDataDefault("EndDefeatBullet",false))
	{
			EffectSet(X,Y,"GREEN");
	}
	Obj_Delete(obj);
}

task StarShot(Cobj,angle,r)
{//̊e_̈ʒuɂe
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj, Obj_GetX(Cobj), Obj_GetY(Cobj));
	ObjShot_SetGraphic(obj, 157);
	//Obj_SetAngle(obj,angle);
	Obj_SetAngle(obj,angle+162);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);
	Obj_SetAlpha(obj,0);
//	Obj_SetCollisionToPlayer(obj,false);
	ObjLaser_SetLength(obj,r*2*sin(72));
	ObjLaser_SetWidth(obj,15);
//ObjLaser_SetSource(obj,false);
	let X;
	let Y;
	let VanishJudg=false;
	let count=0;
	//let r=150;//̒_܂ł̋
	while(!Obj_BeDeleted(Cobj))
	{
		Obj_SetAngle(obj,angle+162);
		//Obj_SetAngle(obj,angle);
		Obj_SetPosition(obj,Obj_GetX(Cobj)+r*cos(angle),Obj_GetY(Cobj)+r*sin(angle));
		if(count>=2)
		{
			LayShot(obj,r);
			count=0;
		}
		angle+=1.1;
		count+=1;
		yield;
	}
	Obj_Delete(obj);
}

task StarCentralShot(let x,let y,let r,let speed,let angle,let graphic,let delay)
{//̒Sɂe̍쐬
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetAngle(obj,angle);
	Obj_SetSpeed(obj,speed);
	ObjShot_SetGraphic(obj, graphic);
//	ObjShot_SetDelay(obj, delay);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAlpha(obj,0);
	Obj_SetAutoDelete(obj,false);

	let X;
	let Y;
	let VanishJudg=false;

	ascent(let i in 0..5)
	{
	StarShot(obj,i*72,r);
	}
	while(Obj_GetY(obj)<GetClipMaxY+128)
	{
		yield;
	}
	Obj_Delete(obj);
}

#include_function ".\..\txt/Data.txt"
#include_function ".\..\lib/lib_anime_Sanae.txt"
}
